<?php
if( !isset($argv[1]) || empty($argv[1]) ){
    exit("名字不能为空");
}
$name = $argv[1];
// 首字母大写
$nameFistBig = ucfirst($name);
// 首字母小写
$nameFist = lcfirst($name);
// 驼峰转下划线
$underlineName = strtolower(preg_replace('/([a-z])([A-Z])/', "$1" . '_' . "$2", $name));

// 读取模板内容 S
$controllerContent = file_get_contents("./template/Controller.template");
$modelContent = file_get_contents("./template/Model.template");
$serviceContent = file_get_contents("./template/Service.template");
$createHtmlContent = file_get_contents("./view/create.html");
$indexHtmlContent = file_get_contents("./view/index.html");
$updateHtmlContent = file_get_contents("./view/update.html");
// 读取模板内容 E

// 替换模板内容 S
$search = [
    '{nameFirstBig}',
    '{nameFirst}',
    '{underlineName}',
];
$replace = [
    $nameFistBig,
    $nameFist,
    $underlineName,
];
$controllerContent = str_replace($search,$replace,$controllerContent);
$modelContent = str_replace($search,$replace,$modelContent);
$serviceContent = str_replace($search,$replace,$serviceContent);
// 替换模板内容 E

// 生成文件 S
file_put_contents("./{$nameFistBig}Controller.php",$controllerContent);
file_put_contents("./{$nameFistBig}Model.php",$modelContent);
file_put_contents("./{$nameFistBig}Service.php",$serviceContent);

mkdir("./{$underlineName}");
file_put_contents("./{$underlineName}/create.html",$createHtmlContent);
file_put_contents("./{$underlineName}/index.html",$indexHtmlContent);
file_put_contents("./{$underlineName}/update.html",$updateHtmlContent);
// 生成文件 E

echo "success";